package com.server.push.mqtt.base;

import com.server.push.mqtt.base.annotation.MqttController;
import lombok.Getter;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@Getter
public class MqttUtilsBean implements BeanPostProcessor, ApplicationContextAware {


    private final List<Object> controllerBeans = new ArrayList<>();
    private final List<Object> filterBeans = new ArrayList<>();


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

        MqttController controllerAnnotation = AnnotationUtils.findAnnotation(bean.getClass(), MqttController.class);
        if (controllerAnnotation != null) {
            this.controllerBeans.add(bean);
        }

        return bean;
    }



}
